<?php
/**
 * Xml解析类
 *
 * @author LeeNux
 * @version 1.0
 */
class Xml {
	/**
	 * 通过数组构造Xml
	 *
	 * @param array $arr        	
	 * @param number $dom        	
	 * @param number $item        	
	 */
	public function arrToXml($arr, $dom = 0, $item = 0) {
		if (! $dom) {
			$dom = new DOMDocument ( "1.0" );
			$dom->encoding = 'utf-8';
		}
		if (! $item) {
			$item = $dom->createElement ( "root" );
			$dom->appendChild ( $item );
		}
		foreach ( $arr as $key => $val ) {
			$itemx = $dom->createElement ( is_string ( $key ) ? $key : "item" );
			$item->appendChild ( $itemx );
			if (! is_array ( $val )) {
				$text = $dom->createTextNode ( $val );
				$itemx->appendChild ( $text );
			} else {
				$this->arrToXml ( $val, $dom, $itemx );
			}
		}
		return $dom->saveXML ();
	}
}